package Year21_Month11.day1107;

public class Solution {
    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0){
            return false;
        }
        int a = matrix.length - 1,b = 0;
        int boundB = matrix[0].length;
        while(a >= 0 && b < boundB){
            if(matrix[a][b] > target){
                a--;
                continue;
            }
            if(matrix[a][b] < target){
                b++;
                continue;
            }
            if(matrix[a][b] == target){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] arr = {{1, 4, 7, 11, 15}, {2, 5, 8, 12, 19}, {3, 6, 9, 16, 22}, {10, 13, 14, 17, 24}, {18, 21, 23, 26, 30}};
        System.out.println(findNumberIn2DArray(arr,20));
    }
}
